using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Xml;

namespace mdv.wssSchemaExplorer.WSS
{
    /// <summary>
    /// http://msdn.microsoft.com/en-us/library/ms478121.aspx
    /// </summary>
    public class wssForm
    {
        #region ctors
        public wssForm() { }
        public wssForm(XmlNode node)
        {
            //required
            if (null != node.Attributes["Type"]) this.Type = (WSS.wssFormType)Enum.Parse(typeof(WSS.wssFormType), node.Attributes["Type"].Value);
            if (null != node.Attributes["Url"]) this.Url = node.Attributes["Url"].Value;
            //optional
            if (null != node.Attributes["Path"]) this.Path = node.Attributes["Path"].Value;
            if (null != node.Attributes["SetupPath"]) this.SetupPath = node.Attributes["SetupPath"].Value;
            if (null != node.Attributes["Template"]) this.Template = node.Attributes["Template"].Value;
            if (null != node.Attributes["UseLegacyForm"]) this.UseLegacyForm = bool.Parse(node.Attributes["UseLegacyForm"].Value);
            if (null != node.Attributes["WebPartZoneID"]) this.WebPartZoneID = node.Attributes["WebPartZoneID"].Value;
        }
        #endregion
        #region Properties
        private string _path;
        [Browsable(true)]
        [Category("Optional")]
        [Description("Specifies the file system path, including the leaf name, of the file containing the template used for the list of document libraries that is rendered in a file dialog box. The value of this attribute is relative to the _layouts directory and does not start with a forward slash (\" / \").")]
        public string Path
        {
            get { return _path; }
            set { _path = value; }
        }
        private string _setupPath;
        [Browsable(true)]
        [Category("Optional")]
        [Description("Specifies the relative path to the folder in the setup directory that contains the .aspx page of the form, for example, pages/form.aspx.")]
        public string SetupPath
        {
            get { return _setupPath; }
            set { _setupPath = value; }
        }
        private string _template;
        [Browsable(true)]
        [Category("Optional")]
        [Description("Specifies the list template to which the form belongs.")]
        public string Template
        {
            get { return _template; }
            set { _template = value; }
        }
        private wssFormType? _type;
        [Browsable(true)]
        [Category("Required")]
        [Description("Indicates the type of form being described and can be one of the following values: DisplayForm, EditForm, or NewForm.")]
        public wssFormType? Type
        {
            get { return _type; }
            set { _type = value; }
        }
        private string _url;
        [Browsable(true)]
        [Category("Required")]
        [Description("Specifies the path to the ASP.NET file used for the form.")]
        public string Url
        {
            get { return _url; }
            set { _url = value; }
        }
        private bool? _useLegacyForm;
        [Browsable(true)]
        [Category("Optional")]
        [Description("Used during upgrade to specify that Windows SharePoint Services use Collaborative Application Markup Language (CAML), as in previous versions of the technology, instead of Web controls, to define the view of an item within a form.")]
        public bool? UseLegacyForm
        {
            get { return _useLegacyForm; }
            set { _useLegacyForm = value; }
        }
        private string _webPartZoneID;
        [Browsable(true)]
        [Category("Optional")]
        [Description("Specifies the zone for the Web Part.")]
        public string WebPartZoneID
        {
            get { return _webPartZoneID; }
            set { _webPartZoneID = value; }
        }
        #endregion
        public override string ToString()
        {
            return Url;
        }
    }
    public enum wssFormType {DisplayForm, EditForm, NewForm};
}